package cz.proks.schoolpupilbook.shared.domain;

import java.util.Date;
import java.util.LinkedList;

public class Mark implements IsIndexableDomain, Comparable<Mark>  {
	private String id;
	private User lector;
	private User student;
	private Course course;
	private Date time;
	private String mark;
	private LinkedList<MarkComment> comments;
	
	public Mark() {
		this.comments = new LinkedList<MarkComment>();
	}	
	
	public Mark(String id, User lector, User student, Course course, Date time, String mark) {
		super();
		this.id = id;
		this.lector = lector;
		this.student = student;
		this.course = course;
		this.time = time;
		this.mark = mark;
		this.comments = new LinkedList<MarkComment>();
	}
	
	public Mark(String id, User lector, User student, Course course, Date time, String mark, LinkedList<MarkComment> comments) {
		super();
		this.id = id;
		this.lector = lector;
		this.student = student;
		this.course = course;
		this.time = time;
		this.mark = mark;
		this.comments = comments;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
		
	public User getLector() {
		return lector;
	}

	public void setLector(User lector) {
		this.lector = lector;
	}
	
	public User getStudent() {
		return student;
	}

	public void setStudent(User student) {
		this.student = student;
	}
	
	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	public Date getTime() {
		return time;
	}
	
	public void setTime(Date time) {
		this.time = time;
	}
	
	public String getMark() {
		return mark;
	}
	
	public void setMark(String mark) {
		this.mark = mark;
	}
		
	public LinkedList<MarkComment> getComments() {
		return comments;
	}

	public void setComments(LinkedList<MarkComment> comments) {
		this.comments = comments;
	}
	
	public void addComment(User contributor, Date time, String comment) {
		getComments().add(new MarkComment(null, this, time, contributor, comment));
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Mark other = (Mark) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	@Override
	public int compareTo(Mark o) {
		return o == null ? 1 : -1 * getTime().compareTo(o.getTime());
	}
}
